package jzqb.controller;

import haha.life.common.CutPageBean;
import io.swagger.annotations.ApiOperation;
import jzqb.bo.QBBKBo;
import jzqb.bo.QBFWAuditBo;
import jzqb.common.Result;
import jzqb.controller.admin.AdminPermissionController;
import jzqb.po.QBFWPo;
import jzqb.service.IQBFWService;
import jzqb.service.QBBKService;
import jzqb.vo.QBBKVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:首页代办提示推送---一小时推送一次
 *
 * @author BaiGe
 * @date: 2021/7/14 10:14
 * @Version 1.0
 */
@RestController
@RequestMapping("/IndexSchedulePush")
public class IndexSchedulePushController {
    @Autowired
    private AdminPermissionController adminPermissionController;
    @Autowired
    private QBBKService qbbkService;
    @Autowired
    private IQBFWService qbfwService;



    @ApiOperation(value = "情报百科推送")
    @PostMapping("/pushQBBK")
    public Result pushQBBK(@RequestBody QBBKBo qbbkBo, HttpServletRequest request) {
        //先判断此人有无审核权限
        Result result = adminPermissionController.showShenHeButton(request);
        Boolean bl = (Boolean) result.getData();
        if (!bl) {//没有审核权限
            return Result.succ(null);
        }
        qbbkBo.setFlag(2);//词条审核
//        qbbkBo.setRecorder(TokenUtils.getCurrentUserId(request));//录入人
        qbbkBo.setStart(qbbkBo.getPage(), qbbkBo.getPageSize());//起始条数
        CutPageBean<QBBKVo> cutPage = qbbkService.showQBBK(qbbkBo);
        return Result.succ(cutPage);
    }

    @ApiOperation(value = "情报服务推送")
    @PostMapping("/pushQBFWAudit")
    public Result pushQBFWAudit(@RequestBody QBFWAuditBo qbfwAuditBo, HttpServletRequest request) {
        //先判断此人有无审核权限
        Result result = adminPermissionController.showQBFWShenHeButton(request);
        Boolean bl = (Boolean) result.getData();
        if (!bl) {//没有审核权限
            return Result.succ(null);
        }
        CutPageBean<QBFWPo> cutPageBean = qbfwService.showQBFWAuditList(qbfwAuditBo, request);
        return Result.succ(cutPageBean);
    }

    @ApiOperation(value = "查询新的待审数据")
    @GetMapping("/findNewAuditData")
    public Result findNewAuditData(HttpServletRequest request) {
        Map<String,Integer>  map=new HashMap();
        //此人有无-->情报服务审核权限
        Result qbfwAudti = adminPermissionController.showQBFWShenHeButton(request);
        //此人有无-->情报百科审核权限
        Result qbbkAudit = adminPermissionController.showShenHeButton(request);
        Boolean qbfwAudtiBl = (Boolean) qbfwAudti.getData();
        Boolean qbbkAuditBl = (Boolean) qbbkAudit.getData();

        if (qbfwAudtiBl){//有情报服务审批权限
            int num = qbfwService.findNewQBFWAuditData(request);
            map.put("pbfw", num);
        }else{
            map.put("pbfw", 0);
        }

        if (qbbkAuditBl){ //有情报百科审核权限
            QBBKBo qbbkBo=new QBBKBo();
            qbbkBo.setFlag(2);//词条审核
            int num = qbbkService.findNewQBFWAuditData(qbbkBo);
            map.put("pbbk",num);
        }else{
            map.put("pbbk", 0);
        }
        return Result.succ(map);
    }


}
